from flask import Flask, render_template, request

app = Flask(__name__)

def gcd(*numbers):
    current_gcd = abs(numbers[0])
    for num in numbers[1:]:
        a, b = current_gcd, abs(num)
        while b:
            a, b = b, a % b
        current_gcd = a
    return current_gcd

@app.route('/', methods=['GET', 'POST'])
def index():
    result = None
    if request.method == 'POST':
        try:
            input_str = request.form['numbers']
            numbers = [int(num.strip()) for num in input_str.split(',') if num.strip()]
            if len(numbers) < 2:
                raise ValueError("至少需要输入两个数字")
            result = gcd(*numbers)
        except ValueError as e:
            result = f"错误: {str(e)}"
    
    return render_template('index.html', result=result)

if __name__ == '__main__':
    app.run(debug=True)